package com.fyl.dto;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public abstract class BaseTreeDTO<R extends BaseTreeDTO> {

    private Object id;

    private Object parentId;

    private List<R> children;

    public void findChildren(List<R> trees) {
        for (R t : trees) {
            if (this.getId().equals(t.getParentId())) {
                t.findChildren(trees);
                if (Objects.isNull(this.children)) {
                    this.children = new ArrayList<>();
                }
                this.children.add(t);
            }
        }
    }

    public Object getId() {
        return id;
    }

    public void setId(Object id) {
        this.id = id;
    }

    public Object getParentId() {
        return parentId;
    }

    public void setParentId(Object parentId) {
        this.parentId = parentId;
    }

    public List<R> getChildren() {
        return children;
    }

    public void setChildren(List<R> children) {
        this.children = children;
    }
}
